<%#
 Copyright 2013-2018 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
package <%=packageName%>.domain;

<%_ if (databaseType === 'couchbase') { _%>
import com.couchbase.client.java.repository.annotation.Field;
<%_ } _%>
import com.fasterxml.jackson.annotation.JsonIgnore;
<%_ if (databaseType === 'sql') { _%>
import org.hibernate.envers.Audited;
<%_ } _%>
<%_ if (!reactive) { _%>
import org.springframework.data.annotation.CreatedBy;
<%_ } _%>
import org.springframework.data.annotation.CreatedDate;
<%_ if (!reactive) { _%>
import org.springframework.data.annotation.LastModifiedBy;
<%_ } _%>
import org.springframework.data.annotation.LastModifiedDate;
<%_ if (databaseType === 'mongodb') { _%>
import org.springframework.data.mongodb.core.mapping.Field;
<%_ } _%>
<%_ if (databaseType === 'sql') { _%>
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
<%_ } _%>

import java.io.Serializable;
import java.time.Instant;
<%_ if (databaseType === 'sql') { _%>
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
<%_ } _%>

/**
 * Base abstract class for entities which will hold definitions for created, last modified by and created,
 * last modified by date.
 */
<%_ if (databaseType === 'sql') { _%>
@MappedSuperclass
@Audited
@EntityListeners(AuditingEntityListener.class)
<%_ } _%>
public abstract class AbstractAuditingEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    <%_ if (!reactive) { _%>
    @CreatedBy
    <%_ } _%>
    <%_ if (databaseType === 'sql') { _%>
    @Column(name = "created_by", nullable = false, length = 50, updatable = false)
    <%_ } _%>
    <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
    @Field("created_by")
    <%_ } _%>
    @JsonIgnore
    private String createdBy;

    @CreatedDate
    <%_ if (databaseType === 'sql') { _%>
    @Column(name = "created_date", nullable = false, updatable = false)
    <%_ } _%>
    <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
    @Field("created_date")
    <%_ } _%>
    @JsonIgnore
    private Instant createdDate = Instant.now();

    <%_ if (!reactive) { _%>
    @LastModifiedBy
    <%_ } _%>
    <%_ if (databaseType === 'sql') { _%>
    @Column(name = "last_modified_by", length = 50)
    <%_ } _%>
    <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
    @Field("last_modified_by")
    <%_ } _%>
    @JsonIgnore
    private String lastModifiedBy;

    @LastModifiedDate
    <%_ if (databaseType === 'sql') { _%>
    @Column(name = "last_modified_date")
    <%_ } _%>
    <%_ if (databaseType === 'mongodb' || databaseType === 'couchbase') { _%>
    @Field("last_modified_date")
    <%_ } _%>
    @JsonIgnore
    private Instant lastModifiedDate = Instant.now();

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Instant getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Instant createdDate) {
        this.createdDate = createdDate;
    }

    public String getLastModifiedBy() {
        return lastModifiedBy;
    }

    public void setLastModifiedBy(String lastModifiedBy) {
        this.lastModifiedBy = lastModifiedBy;
    }

    public Instant getLastModifiedDate() {
        return lastModifiedDate;
    }

    public void setLastModifiedDate(Instant lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }
}
